package com.example.sse.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 配置测试控制器
 * 用于测试配置值是否正确注入
 */
@RestController
@RequestMapping("/api/config")
public class ConfigTestController {

    @Value("${server.port:8080}")
    private String serverPort;

    @Value("${sse.connection.timeout:300000}")
    private Long connectionTimeout;

    @Value("${spring.application.name:unknown}")
    private String applicationName;

    /**
     * 获取所有配置信息
     * @return 配置信息
     */
    @GetMapping("/info")
    public ResponseEntity<Map<String, Object>> getConfigInfo() {
        Map<String, Object> configInfo = new HashMap<>();
        configInfo.put("serverPort", serverPort);
        configInfo.put("connectionTimeout", connectionTimeout);
        configInfo.put("applicationName", applicationName);
        configInfo.put("timestamp", System.currentTimeMillis());
        
        return ResponseEntity.ok(configInfo);
    }
}